package com.yeung.exam;

import java.util.Scanner;

/*
2
10_123_50_A0 1566918054
10_123_50_A1 1566918054
10_123_50_A1 1566918055
10_123_50_A3 1566918055
10_123_50_A4 1566918056
 */
public class 搜狗_自定义map {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = Integer.parseInt(sc.nextLine());
        UMap uMap = new UMap(count);
        while (sc.hasNextLine()) {
            String line=sc.nextLine();
            if(line!=null&&!line.equals("")){
                String[] input = line.split(" ");
                uMap.put(input[0], Long.parseLong(input[1]));
            }
        }


    }

    static class UMap {
        int capacity;
        Node[] table;
        int size = 0;

        public UMap(int capacity) {
            this.capacity = capacity;
            this.table = new Node[capacity];
        }

        public void put(String key, long val) {
            Node newKV = new Node(key, val);
            int index = indexFor(key);
            Node oldKV = table[index];
            if (oldKV == null) {
                //不存在
                table[index] = newKV;
                size += 1;
            } else {
                //存在, 视情况更新
                if (oldKV.key.equals(key)) {
                    if (oldKV.value < newKV.value) {
                        oldKV.value = newKV.value;
                    }
                } else {
                    System.out.println(oldKV.key + " " + oldKV.value);
                    table[index] = newKV;
                }
            }
        }


        public int indexFor(String key) {
            int index = -1;
            for (int i = 0; i < size; i++) {
                if (table[i].key.equals(key)) {
                    index = i;
                    break;
                }
            }
            //没有找到已存在的key
            if (index == -1) {
                //那就看是否size达到容量
                if (size < capacity) {
                    index = size;
                } else {
                    //达到容量
                    long mostOldTime = Long.MAX_VALUE;
                    for (int i = 0; i < capacity; i++) {
                        if (table[i].setTime < mostOldTime) {
                            index = i;
                            mostOldTime = table[i].setTime;
                        }
                    }
                }

            }
            return index;
        }
    }

    static class Node {
        String key;
        long value;
        long setTime;

        public Node(String key, long value) {
            this.key = key;
            this.value = value;
            this.setTime = System.currentTimeMillis();
        }
    }
}
